package TeacherEvaluation.com.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import TeacherEvaluation.com.entity.Student;
import TeacherEvaluation.com.entity.Teacher;
import TeacherEvaluation.com.service.pollService;
import TeacherEvaluation.com.service.scoreService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Controller
public class scoreController {
	@Autowired
	scoreService scoreService;
	@Autowired
	pollService pollService;
	
	@RequestMapping("/seleScore")
	ModelAndView SeleMark(HttpServletRequest request, HttpServletResponse response) {
		
		//获取student
		HttpSession session=request.getSession();
		Student user=(Student)session.getAttribute("user");
		ModelAndView mView = new ModelAndView("students/studentScore");
		mView.addObject("SelectScore", scoreService.selectStuScore(user.getId()));
		return mView;
	}
	
	@RequestMapping("/seleTeScore")
	ModelAndView seleTeScore(HttpServletRequest request, HttpServletResponse response) {
		
		//获取student
		HttpSession session=request.getSession();
		Teacher user=(Teacher)session.getAttribute("user");
		ModelAndView mView = new ModelAndView("teachers/teacherScore");
		mView.addObject("te_score", scoreService.selectByMySc(user.getTe_id()));;
		return mView;
	}
	
	@RequestMapping("/selectTeByMy")
	ModelAndView selectTeByMy(HttpServletRequest request, HttpServletResponse response) {
		
		//获取student
		HttpSession session=request.getSession();
		Teacher user=(Teacher)session.getAttribute("user");
		ModelAndView mView = new ModelAndView("teachers/otherTeacher");
		mView.addObject("te_score", scoreService.selectTeByMy(user.getTe_id()));;
		return mView;
	}
	
	@RequestMapping("/showScore")
	ModelAndView stuMark(String as_id) {
		JSONObject jo = new JSONObject();
		JSONArray ja = JSONArray.fromObject(pollService.selectPoByAs(Integer.parseInt(as_id)));
		jo.put("poll", ja);
		ModelAndView mView = new ModelAndView("admin/score/showScore");
		
		mView.addObject("polljson", jo);
		mView.addObject("poll", pollService.selectPoByAs(Integer.parseInt(as_id)));
		mView.addObject("stuScore",scoreService.selectStuScOne(Integer.parseInt(as_id)));
		return mView;
	}
	
	@RequestMapping("/selectStuScore")
	ModelAndView SeleStuMark() {
		ModelAndView mView = new ModelAndView("admin/score/selectStuScore");
		mView.addObject("stuScore",scoreService.selectStuSc());
		return mView;
	}
	
	@RequestMapping("/selectTeScore")
	ModelAndView selectTe() {
		ModelAndView mView = new ModelAndView("admin/score/selectTeScore");
		mView.addObject("te_score",scoreService.selectTe());
		return mView;
	}
	
}
